/**
 * Created by baiguiren on 2/16/17.
 */


// let test = function () {
//   return new Promise(function (resolve, reject) {
//     reject('test error');
//   });
// };
//
// test().then(function (res) {
//   console.log(res)
// }).catch(function (error) {
//   console.log(error);
// });

let promise = new Promise((resolve, reject)=>{
  let flag = false;
  if (flag) {
    resolve();
  } else {
    reject();
  }
}).then(()=>{}).catch(()=>{});


let fs = require('fs');
let bluebird = require('bluebird');
bluebird.promisifyAll(fs);

fs.readFileAsync(__dirname + '/test.json', 'utf8').then(JSON.parse).then(p=>{console.log(p.name)});

new bluebird(function (resolve, reject) {
  resolve('1asdl')
}).then(res=>{console.log(res)});

let clog = console.log;
new Promise(function (resolve, reject) {
  //reject('error');
  throw new SyntaxError('actually nothing wrong.');
}).then(r=>{clog(r);}, r=>{clog(r + 1);}).catch(err=>{console.log('reject', err)});

(new Promise(function (resolve, reject) {
  //resolve(123);
  reject(123);
})).then(function (data) {
  console.log(data);
}).catch(function (data) {
  console.log(data)
});